<template>
  <div><h1>正在登录中…………</h1></div>

</template>

<script>
export default {
  name: "CallBackView",
  data(){
    return{

    }
  },methods:{
    login(){
      let win=location.search;
      let str=win.split("=");
      if(str.length<=2){
        this.axios.post("http://localhost:8003/api/tb-user/giteeLogin?code="+str[1]).then(res=>{
          let a=JSON.parse(res.data.name);
         // alert(res.data.token)
          localStorage.setItem("name",a.name);
          localStorage.setItem("token",res.data.token);
          localStorage.setItem("avatar",a.avatar_url);
          this.$router.push("/list");
        })
      }
      else{
        let code=str[1].split("&")[0]
        this.axios.post("http://localhost:8003/api/tb-user/getOauthLogin?code="+code).then(res=>{
          localStorage.setItem("token",res.data.token);
          localStorage.setItem("name",res.data.name);
          this.$message.success("登录成功")
          this.$router.push("/list");
        })
      }
    }
  },created() {
    this.login();
  }
}
</script>

<style scoped>

</style>